<?php

// The HTML href link wrapper function
function template_href_link($params, &$smarty)
{
	global $request_type, $session, $SID;
	
	$page = (isset($params['page'])) ? $params['page'] : '';
	$params = (isset($params['params'])) ? $params['params'] : '';
	$ssl = (isset($params['ssl']) && $params['ssl']) ? true : false;
	$add_session_id = (isset($params['add_session']) && $params['add_session']) ? true : false;
	$search_engine_safe = (isset($params['se_safe']) && $params['se_safe']) ? true : false;
	
	if (!tep_not_null($page))
	{
		echo '<br /><br /><strong>Error!</strong><br />Unable to determine the page link!';
		exit(0);
	}
	
	$link = ($ssl && ENABLE_SSL == true) ? HTTPS_SERVER.DIR_WS_HTTPS_CATALOG : HTTP_SERVER.DIR_WS_HTTP_CATALOG;
	$link .= $page;
	$link .= (tep_not_null($params)) ? '?'.tep_output_string($params) : '';
	$separator = (tep_not_null($params)) ? '&' : '?';
	
	while ((substr($link, -1) == '&') || (substr($link, -1) == '?'))
	{
		$link = substr($link, 0, -1);
	}
	
	// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
	if (($add_session_id == true) && ($session->started()) && (SESSION_FORCE_COOKIE_USE == 'False'))
	{
		if (tep_not_null($SID))
		{
			$_sid = $SID;
		}
		
		elseif (($request_type=='NONSSL' && $ssl && ENABLE_SSL==true) || ($request_type=='SSL' && !$ssl))
		{
			if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN)
			{
				$_sid = $session->getName().'='.$session->getId();
			}
		}
	}
	
	if (SEARCH_ENGINE_FRIENDLY_URLS=='true' && $search_engine_safe)
	{
		while (strstr($link, '&&'))
		{
			$link = str_replace('&&', '&', $link);
		}
		
		$link = str_replace('?', '/', $link);
		$link = str_replace('&', '/', $link);
		$link = str_replace('=', '/', $link);
		$separator = '?';
	}
	
	$link .= (isset($_sid)) ? $separator.$_sid : '';
	
	return $link;
}

function template_all_params($params, &$smarty)
{
	if (array_key_exists('exclude', $params))
	{
		$exclude = explode(',', $params['exclude']);
		return tep_get_all_get_params($exclude);
	}
	
	return tep_get_all_get_params();
}

function template_strftime($params, &$smarty)
{
	$format = $params['format'];
	
	if (array_key_exists('date', $params))
	{
		$date = $params['date'];
	}
	
	else
	{
		$date = time();
	}
	
	return strftime($format, $date);
}

function template_date_short($params, &$smarty)
{
	return tep_date_short($params['date']);
}

function template_date_long($params, &$smarty)
{
	return tep_date_long($params['date']);
}

function template_display_banner($params, &$smarty)
{
	$size = (array_key_exists('size', $params)) ? $params['size'] : '468x50';
	
	if ($params['type'] == 'dynamic')
	{
		if ($banner = tep_banner_exists('dynamic', $size))
		{
			return tep_display_banner('static', $banner);
		}
	}
	
	elseif ($params['type'] == 'static')
	{
		$banner = array(
			'banners_id' => $params['id'],
			'banners_title' => $params['title'],
			'banners_image' => 'banners/'.$params['image'],
			'banners_html_text' => $params['text']
		);
		return tep_display_banner('static', $banner);
	}
}

function template_output_string_protected($params, &$smarty)
{
	return tep_output_string_protected($params['text']);
}

function template_break_string($params, &$smarty)
{
	return tep_break_string($params['text'], $params['size'], $params['separator']);
}

function template_create_sort_heading($params, &$smarty)
{
	return tep_create_sort_heading($params['sortcol'], $params['colid'], $params['text']);
}

function template_get_zone_name($params, &$smarty)
{
	return tep_get_zone_name($params['country'], $params['zone'], $params['state']);
}

?>
